package org.lgh.wallet.controller;

import org.lgh.wallet.common.R;
import org.lgh.wallet.dto.ConsumeDTO;
import org.lgh.wallet.dto.DrawbackDTO;
import org.lgh.wallet.service.WalletService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author wei-xhh
 * @date 2023-02-27
 */
@RestController
@RequestMapping("/wallet")
public class WalletController {

    @Resource
    private WalletService walletService;

    /**
     * 根据ID获取钱包记录
     * @param userId 用户ID
     * @return 结果
     */
    @GetMapping("/getByUserId")
    public R<Object> getByUserId(@RequestParam(required = true) Long userId) {
        return walletService.getByUserId(userId);
    }

    @PostMapping("/consume")
    public R<Object> consume(@RequestBody @Validated ConsumeDTO param) {
        return walletService.consume(param);
    }

    @PostMapping("/drawback")
    public R<Object> drawback(@RequestBody @Validated DrawbackDTO param) {
        return walletService.drawback(param);
    }

    @GetMapping("/getDetail")
    public R<Object> getDetail(@RequestParam(required = true) Long walletId) {
        return walletService.getDetail(walletId);
    }
}
